package com.design.pattern.behavior.delegate.general;

import java.util.Random;

/**
 * 委派 角色
 */
public class Delegate implements Task{
    private Task concreteA = new ConcreteA();
    private Task concreteB = new ConcreteB();
    @Override
    public void doTask() {
        System.out.println("代理执行开始");
        Task task = null;
        if(new Random().nextBoolean()) {
            task = new ConcreteA();
        }else {
            task = new ConcreteB();
        }
        task.doTask();
        System.out.println("代理执行完毕！");
    }

}
